<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>侦听属性</title>
    <script src="node_modules/vue/dist/vue.js"></script>
</head>
<body>
<div id="demo">{{ fullName }}</div>

<script>
//    var vm = new Vue({
//        el: '#demo',
//        data: {
//            firstName: 'Foo',
//            lastName: 'Bar',
//            fullName: 'Foo Bar'
//        },
//        watch: {
//            firstName: function (val) {
//                this.fullName = val + ' ' + this.lastName
//            },
//            lastName: function (val) {
//                this.fullName = this.firstName + ' ' + val
//            }
//        }
//    })

    var vm = new Vue({
        el: '#demo',
        data: {
            firstName: 'Foo',
            lastName: 'Bar'
        },
        computed: {
            fullName: function () {
                return this.firstName + ' ' + this.lastName
            }
        }
    })
</script>
</body>
</html>